<%--
  Created by IntelliJ IDEA.
  User: 匹诺曹
  Date: 2023/12/15
  Time: 17:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<div class="skin-default" id="wrapper">
    <%@ include file="/static/pages/head/header.jsp" %>
    <%--中间内容--%>
    <div class="page-wrapper">
        <section class="page-body">
            <div class="row widget">
                <section class="col-md-12">
                    <div class="box table">
                        <div class="box-header">
                            <h3 class="box-title">菜单信息展示</h3>
                            <br/>
                            <a class="btn btn-success" style="margin-top: 20px;" data-target=".update" data-toggle="modal" title="add">添加一级菜单</a>
                        </div>
                        <div class="box-body">
                            <table id="table" class="table table-responsive table-hover">
                                <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>菜单名称</th>
                                    <th>菜单等级</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach items="${menuList}" var="menu">
                                    <tr>
                                        <td>${menu.menuId}</td>
                                        <td>${menu.menuName}</td>
                                        <td>
                                            <c:if test="${menu.menuLevelid==1}">一级菜单</c:if>
                                            <c:if test="${menu.menuLevelid==2}">二级菜单</c:if>
                                        </td>
                                        <td>
                                            <a class="btn btn-primary" href="${pageContext.request.contextPath}/menu/menuList2/${menu.menuId}">展示二级菜单</a>
                                            <a class="btn btn-info" data-target=".update" data-toggle="modal"
                                               onclick="update(${menu.menuId})">修改</a>
                                            <a class="btn btn-danger"
                                               href="${pageContext.request.contextPath}/menu/deleteByMenuId/${menu.menuId}">删除</a>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </section>
            </div>
        </section>
    </div>
    <div class="modal fade power" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">赋权</h4>
                </div>
                <form method="post" action="${pageContext.request.contextPath}/user/updateById">
                    <input type="hidden" name="userId" title="userId">
                    <div class="modal-body">
                        <select name="roleId">
                            <option value="-1">请选择</option>
                            <c:forEach items="${roleList}" var="role">
                                <option value="${role.roleId}">${role.roleName}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- Small modal -->
    <div class="modal fade update" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">修改/添加</h4>
                </div>
                <form method="post" action="${pageContext.request.contextPath}/menu/add">
                    <div class="modal-body">
                        <div class="modal-body">
                            <div class="form-group">
                                <label>MenuId</label>
                                <input type="text" class="form-control" placeholder="MenuId" name="menuId" readonly>
                            </div>
                            <div class="form-group">
                                <label>MenuName</label>
                                <input type="text" class="form-control" placeholder="MenuName" name="menuName">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="submit" class="btn btn-primary">提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script>
        $(function () {
        })

        function power(roleId, userId) {
            $("[title='userId']").val(userId);
            console.log(roleId + "\t" + userId);
            $.ajax({
                type: "GET",
                url: "${pageContext.request.contextPath}/role/findById/" + roleId,
                dataType: "json",
                success: function (res) {
                    console.log(res)
                    if (res != null) {
                        $("[name='roleId']").val(res.roleId);
                    }
                }
            })
        }

        function update(menuId) {
            $.ajax({
                type: "GET",
                url: "${pageContext.request.contextPath}/menu/findById/" + menuId,
                dataType: "json",
                success: function (menu) {
                    $("[name='menuId']").val(menu.menuId);
                    $("[name='menuName']").val(menu.menuName);
                }
            })
        }
        $("[title='add']").click(function (){
            $("[name='menuId']").val("");
            $("[name='menuName']").val("");
        })


    </script>
</body>

</html>
